package com.jcl.cloud.services.crawler.brain;

import com.jcl.cloud.services.crawler.brain.service.RedisService;
import com.jcl.cloud.services.crawler.brain.task.WorkerDispatcher;
import com.jcl.cloud.services.crawler.brain.thread.TaskWatchThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.ApplicationContext;
import org.springframework.core.task.SimpleAsyncTaskExecutor;

@EnableDiscoveryClient
@SpringBootApplication
@EnableEurekaClient
public class CrawlerBrainMicroService {
    private final static Logger logger = LoggerFactory.getLogger(CrawlerBrainMicroService.class);


    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(CrawlerBrainMicroService.class, args);
        startDispatch(context);
    }


    public static void startDispatch(ApplicationContext context) {
        logger.info("------- Worker任务处理正在启动...... -------");
        SimpleAsyncTaskExecutor cmdDispatchExecutor = new SimpleAsyncTaskExecutor();
        cmdDispatchExecutor.setDaemon(true);
        cmdDispatchExecutor.execute((WorkerDispatcher) context.getBean("grabWorkerDispatcher"));
        cmdDispatchExecutor.execute((WorkerDispatcher)context.getBean("grabBuyResumeWorkerDispatcher"));
        //RedisService redisService = (RedisService) context.getBean("redisService");
        //TaskWatchThread taskWatchThread = new TaskWatchThread(redisService);
        //cmdDispatchExecutor.execute(taskWatchThread);
        logger.info("------- Worker任务处理启动完毕...... -------");
    }


    public static void test(ApplicationContext context){

        RedisService redisService = (RedisService) context.getBean("redisService");

        System.out.println(redisService.get("test"));
    }




}
